package my.design.combination.service.logic.impl;

import my.design.combination.model.vo.TreeNodeLink;
import my.design.combination.service.logic.LogicFilter;

import java.util.List;
import java.util.Map;

/**
 * @author zp
 * @version 1.0
 * @description: 处理器的抽象类 定义了处理器的基本实现
 * @date 2022/10/13 20:38
 */
public abstract class BaseLogic implements LogicFilter {

    public Long filter(String matterValue, List<TreeNodeLink>
            treeNodeLinkList) {
        for (TreeNodeLink nodeLine : treeNodeLinkList) {
            if (decisionLogic(matterValue, nodeLine)) {
                return nodeLine.getNodeIdTo();
            }
        }
        return 0L;
    }

    public abstract String matterValue(Long treeId, String userId,
                                       Map<String, String> decisionMatter);

    private boolean decisionLogic(String matterValue, TreeNodeLink nodeLink) {
        switch (nodeLink.getRuleLimitType()) {
            case 1:
                return matterValue.equals(nodeLink.getRuleLimitValue());
            case 2:
                return Double.parseDouble(matterValue) >
                        Double.parseDouble(nodeLink.getRuleLimitValue());
            case 3:
                return Double.parseDouble(matterValue) <
                        Double.parseDouble(nodeLink.getRuleLimitValue());
            case 4:
                return Double.parseDouble(matterValue) <=
                        Double.parseDouble(nodeLink.getRuleLimitValue());
            case 5:
                return Double.parseDouble(matterValue) >=
                        Double.parseDouble(nodeLink.getRuleLimitValue());
            default:
                return false;
        }
    }
}
